package com.example.bigevent.mapper;

import com.example.bigevent.pojo.Game;
import com.example.bigevent.pojo.Review;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface GameMapper {
    @Insert("INSERT INTO game (id, name, description, price) VALUES (#{id}, #{name}, #{description}, #{price})")
    void insert(Game game);

    @Select("SELECT * FROM game")
    List<Game> selectAll();

    @Select("SELECT * FROM game WHERE id = #{id}")
    Game selectById(Integer id);

    @Insert("INSERT INTO review (game_id, content) VALUES (#{gameId}, #{review.content})")
    void insertReview(@Param("gameId") Integer gameId, @Param("review") Review review);

    @Insert("UPDATE game SET purchased = true WHERE id = #{id}")
    void purchase(Integer id);

    @Select("SELECT * FROM review WHERE game_id = #{gameId}")
    List<Review> selectReviewsByGameId(Integer gameId);
}